// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Main
{
	using System;
	using System.IO;
	using System.Windows.Forms;

	public sealed partial class CreateNewFile : Form
	{
		#region Fields

		private readonly int ID;
		private readonly int Index;
		private readonly string Path;

		#endregion Fields

		#region Constructors

		public CreateNewFile(string path, int fileType, int projectType)
		{
			InitializeComponent();
			Path = path + "\\";
			Index = fileType;
			ID = projectType;
			textBox2.Text = Path;
		}

		#endregion Constructors

		#region Methods

		private void CreateFile()
		{
			string ext = "";
			if (!checkBox1.Checked) {
				if (ID == 0) {
					ext = Index == 0 ? ".cpp" : ".h";
				} else
					ext = ".cs";
			}
			try {
				if (ext != "") {
					FileStream f = File.Create(Path + txtFileName.Text + ext);
					f.Close();
				} else {
					FileStream f = File.Create(Path + txtFileName.Text);
					f.Close();
				}
			}
			catch (Exception ex) {
				MessageBox.Show(ex.Message, "CodingEditor", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
		}

		private void CreateNewFile_FormClosing(object sender, FormClosingEventArgs e)
		{
			Dispose(true);
		}

		private void btnCanc_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			if (txtFileName.Text != "") {
				CreateFile();
				Close();
			} else
				MessageBox.Show("Specify a File Name first !", "CodingEditor", MessageBoxButtons.OK, MessageBoxIcon.Stop);
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			groupBox1.Text = (checkBox1.Checked) ? "File Name [FileName + Extension]" : "File Name [FileName Only]";
		}

		#endregion Methods
	}
}